<?php

/**
 * This is the model class for table "site_gallery".
 *
 * The followings are the available columns in table 'site_gallery':
 * @property string $gallery_id
 * @property string $gallery_gallery_category_id
 * @property string $gallery_title
 * @property string $gallery_description
 * @property string $gallery_image
 * @property string $gallery_input_datetime
 * @property string $gallery_is_active
 *
 * The followings are the available model relations:
 * @property SiteGalleryCategory $galleryGalleryCategory
 */
class site_gallery extends CActiveRecord {

    /**
     * Returns the static model of the specified AR class.
     * @return site_gallery the static model class
     */
    public static function model($className=__CLASS__) {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName() {
        return 'site_gallery';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules() {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('gallery_title', 'required'),
            array('gallery_gallery_category_id', 'length', 'max' => 10),
            array('gallery_title', 'length', 'max' => 100),
            array('gallery_image', 'length', 'max' => 255),
            array('gallery_is_active', 'length', 'max' => 1),
            array('gallery_description, gallery_input_datetime', 'safe'),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('gallery_id, gallery_gallery_category_id, gallery_title, gallery_description, gallery_image, gallery_input_datetime, gallery_is_active', 'safe', 'on' => 'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations() {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
            'rel_gallery_to_gallery_category' => array(self::BELONGS_TO, 'site_gallery_category', 'gallery_gallery_category_id'),
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels() {
        return array(
            'gallery_id' => 'Gallery',
            'gallery_gallery_category_id' => 'Gallery Category',
            'gallery_title' => 'Gallery Title',
            'gallery_description' => 'Description',
            'gallery_image' => 'Image',
            'gallery_input_datetime' => 'Input Date',
            'gallery_is_active' => 'Is Active',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search() {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria = new CDbCriteria;

        $criteria->compare('gallery_id', $this->gallery_id, true);
        $criteria->compare('gallery_gallery_category_id', $this->gallery_gallery_category_id, true);
        $criteria->compare('gallery_title', $this->gallery_title, true);
        $criteria->compare('gallery_description', $this->gallery_description, true);
        $criteria->compare('gallery_image', $this->gallery_image, true);
        $criteria->compare('gallery_input_datetime', $this->gallery_input_datetime, true);
        $criteria->compare('gallery_is_active', $this->gallery_is_active, true);

        return new CActiveDataProvider($this, array(
            'criteria' => $criteria,
        ));
    }

}